<!doctype html>
<html class="default no-js">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Subscription | React Native Background Geolocation</title>
	<meta name="description" content="Documentation for React Native Background Geolocation">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="../assets/css/main.css">
	<link rel="shortcut icon" class="favicon" href="../assets/images/favicon.ico">
	<script src="../assets/js/search.js"></script>
</head>
<body>
<header>
	<div class="tsd-page-toolbar">
		<div class="container">
			<div class="table-wrap">
				<div class="table-cell left">
					<div class="brand">
						<a class="logo" href="https://www.transistorsoft.com"><img src="../assets/images/transistor-logo-bw.svg" /></a>
						<span class="title">
							<a href="/react-native-background-geolocation">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 4.18.0</span>
						</span>
					</div>
				</div>
				<div class="table-cell" id="tsd-search" data-index="../assets/js/search.json" data-base="..">
					<div class="field">
						<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
						<input id="tsd-search-field" type="text" />
					</div>
					<ul class="results">
						<li class="state loading"></li>
						<li class="state failure">The search index is not available</li>
					</ul>
				</div>
				<div class="table-cell" id="tsd-widgets">
					<div id="tsd-filter">
						<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
						<div class="tsd-filter-group">
							<div class="tsd-select" id="tsd-filter-visibility">
								<span class="tsd-select-label">All</span>
								<ul class="tsd-select-list">
									<li data-value="public">Public</li>
									<li data-value="protected">Public/Protected</li>
									<li data-value="private" class="selected">All</li>
								</ul>
							</div>
							<input type="checkbox" id="tsd-filter-inherited" checked />
							<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
						</div>
					</div>
					<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
				</div>
			</div>
		</div>
	</div>
	<div class="tsd-page-title">
		<div class="container">
			<ul class="tsd-breadcrumb">
				<li>
					<a href="../index.html">React Native Background Geolocation</a>
				</li>
				<li>
					<a href="subscription.html">Subscription</a>
				</li>
			</ul>
			<h1>Interface Subscription</h1>
		</div>
	</div>
</header>
<div class="container container-main">
	<div class="row">
		<div class="col-9 col-content">
			<section class="tsd-panel tsd-comment">
				<div class="tsd-comment tsd-typography">
					<div class="lead">
						<p>Object returned by BackgroundGeolocation event-listeners.  <code>Subscription</code> contains just a single method <a href="subscription.html#remove">remove</a>, used for removing an event-listener.</p>
					</div>
					<ul>
						<li><a href="../classes/backgroundgeolocation.html#onlocation">BackgroundGeolocation.onLocation</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onmotionchange">BackgroundGeolocation.onMotionChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onhttp">BackgroundGeolocation.onHttp</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onheartbeat">BackgroundGeolocation.onHeartbeat</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onproviderchange">BackgroundGeolocation.onProviderChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onactivitychange">BackgroundGeolocation.onActivityChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#ongeofence">BackgroundGeolocation.onGeofence</a></li>
						<li><a href="../classes/backgroundgeolocation.html#ongeofenceschange">BackgroundGeolocation.onGeofencesChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onenabledchange">BackgroundGeolocation.onEnabledChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onconnectivitychange">BackgroundGeolocation.onConnectivityChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onschedule">BackgroundGeolocation.onSchedule</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onpowersavechange">BackgroundGeolocation.onPowerSaveChange</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onnotificationaction">BackgroundGeolocation.onNotificationAction</a></li>
						<li><a href="../classes/backgroundgeolocation.html#onauthorization">BackgroundGeolocation.onAuthorization</a></li>
					</ul>
					<p>In the past, one would remove event-listeners using the <strong>now-deprectated</strong> <a href="../classes/backgroundgeolocation.html#removelistener">BackgroundGeolocation.removeListener</a>.</p>
					<a href="#removing-an-event-listener" id="removing-an-event-listener" style="color: inherit; text-decoration: none;">
						<h2>Removing an event-listener:</h2>
					</a>
					<dl class="tsd-comment-tags">
						<dt class="tsd-comment-tag-example">example</dt>
						<dd><pre><code class="language-typescript"><span style="color: #88846F">// Event-listeners return a Subscription instance, containing a .remove() method.</span>
<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> subscription </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> BackgroundGeolocation.</span><span style="color: #A6E22E">onLocation</span><span style="color: #F8F8F2">(</span><span style="color: #FD971F">location</span><span style="color: #F8F8F2"> </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  console.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&quot;[onLocation] &quot;</span><span style="color: #F8F8F2">, location);</span>
<span style="color: #F8F8F2">});</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #88846F">// Later, to remove the event-listener:</span>
<span style="color: #F8F8F2">subscription.</span><span style="color: #A6E22E">remove</span><span style="color: #F8F8F2">();</span>
</code></pre>
							<p>One might typically manage a collection of <code>Subscription</code> instances</p>
						</dd>
						<dt class="tsd-comment-tag-example">example</dt>
						<dd><pre><code class="language-typescript"><span style="color: #F92672">import</span><span style="color: #F8F8F2"> BackgroundGeolocation, {</span>
<span style="color: #F8F8F2">  Location,</span>
<span style="color: #F8F8F2">  Subscription</span>
<span style="color: #F8F8F2">} </span><span style="color: #F92672">from</span><span style="color: #F8F8F2"> ...</span>

<span style="color: #88846F">// Your custom Collection of Subscription instances.</span>
<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> SUBSCRIPTIONS </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> [];</span>

<span style="color: #88846F">// Your custom method to push a Subscription instance.</span>
<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> </span><span style="color: #A6E22E">subscribe</span><span style="color: #F8F8F2"> </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> (</span><span style="color: #FD971F">subscription</span><span style="color: #F92672">:</span><span style="color: #A6E22E">Subscription</span><span style="color: #F8F8F2">) </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  SUBSCRIPTIONS.</span><span style="color: #A6E22E">push</span><span style="color: #F8F8F2">(subscription);</span>
<span style="color: #F8F8F2">}</span>

<span style="color: #88846F">// Your custom method to interate your SUBSCRIPTIONS and .remove each.</span>
<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> </span><span style="color: #A6E22E">unsubscribe</span><span style="color: #F8F8F2"> </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> () </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  SUBSCRIPTIONS.</span><span style="color: #A6E22E">forEach</span><span style="color: #F8F8F2">((</span><span style="color: #FD971F">subscription</span><span style="color: #F92672">:</span><span style="color: #A6E22E">Subscription</span><span style="color: #F8F8F2">) </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> subscription.</span><span style="color: #A6E22E">remove</span><span style="color: #F8F8F2">());</span>
<span style="color: #F8F8F2">}</span>

<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> initBackgroundGeolocation </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> () {</span>
<span style="color: #F8F8F2">  </span><span style="color: #88846F">// Create event-listeners as usual, feeding the returned Subscription into</span>
<span style="color: #F8F8F2">  </span><span style="color: #88846F">// your custom  subscribe() method.</span>
<span style="color: #F8F8F2">  </span><span style="color: #A6E22E">subscribe</span><span style="color: #F8F8F2">(BackgroundGeolocation.onLocation((</span><span style="color: #FD971F">location</span><span style="color: #F92672">:</span><span style="color: #A6E22E">Location</span><span style="color: #F8F8F2">) </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">    </span><span style="color: #A6E22E">console</span><span style="color: #F8F8F2">.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&#039;[onLocation]&#039;</span><span style="color: #F8F8F2">, </span><span style="color: #A6E22E">location</span><span style="color: #F8F8F2">);</span>
<span style="color: #F8F8F2">  });</span>

<span style="color: #F8F8F2">  </span><span style="color: #A6E22E">subscribe</span><span style="color: #F8F8F2">(BackgroundGeolocation.onMotionChange((</span><span style="color: #FD971F">location</span><span style="color: #F92672">:</span><span style="color: #A6E22E">Location</span><span style="color: #F8F8F2">) </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">    </span><span style="color: #A6E22E">console</span><span style="color: #F8F8F2">.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&#039;[onMotionChange]&#039;</span><span style="color: #F8F8F2">, </span><span style="color: #A6E22E">location</span><span style="color: #F8F8F2">);</span>
<span style="color: #F8F8F2">  });</span>

<span style="color: #F8F8F2">  </span><span style="color: #A6E22E">subscribe</span><span style="color: #F8F8F2">(BackgroundGeolocation.onEnabledChange((</span><span style="color: #FD971F">enabled</span><span style="color: #F92672">:</span><span style="color: #66D9EF">boolean</span><span style="color: #F8F8F2">) </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">    </span><span style="color: #A6E22E">console</span><span style="color: #F8F8F2">.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&#039;[onEnabledChange]&#039;</span><span style="color: #F8F8F2">, </span><span style="color: #A6E22E">enabled</span><span style="color: #F8F8F2">);</span>
<span style="color: #F8F8F2">  });</span>
<span style="color: #F8F8F2">}</span>

<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> </span><span style="color: #A6E22E">onDestroyView</span><span style="color: #F8F8F2"> </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> () </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  </span><span style="color: #88846F">// Call your custom unsubscribe method</span>
<span style="color: #F8F8F2">  </span><span style="color: #A6E22E">unsubscribe</span><span style="color: #F8F8F2">();</span>
<span style="color: #F8F8F2">}</span>

</code></pre>
						</dd>
					</dl>
				</div>
			</section>
			<section class="tsd-panel tsd-hierarchy">
				<h3>Hierarchy</h3>
				<ul class="tsd-hierarchy">
					<li>
						<span class="target">Subscription</span>
					</li>
				</ul>
			</section>
			<section class="tsd-panel-group tsd-index-group">
				<h2>Index</h2>
				<section class="tsd-panel tsd-index-panel">
					<div class="tsd-index-content">
						<section class="tsd-index-section ">
							<h3>Methods</h3>
							<ul class="tsd-index-list">
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="subscription.html#remove" class="tsd-kind-icon">remove</a></li>
							</ul>
						</section>
					</div>
				</section>
			</section>
			<section class="tsd-panel-group tsd-member-group ">
				<h2>Methods</h2>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="remove" class="tsd-anchor"></a>
					<h3>remove</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">remove<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>Removes a <code>BackgroundGeolocation</code> event-listener.</p>
								</div>
								<dl class="tsd-comment-tags">
									<dt class="tsd-comment-tag-example">example</dt>
									<dd><pre><code class="language-typescript"><span style="color: #88846F">// Event-listeners return a Subscription instance, containing a .remove() method.</span>
<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> onLocationSubscription </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> BackgroundGeolocation.</span><span style="color: #A6E22E">onLocation</span><span style="color: #F8F8F2">(</span><span style="color: #FD971F">location</span><span style="color: #F8F8F2"> </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  console.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&quot;[onLocation] &quot;</span><span style="color: #F8F8F2">, location);</span>
<span style="color: #F8F8F2">});</span>

<span style="color: #66D9EF">const</span><span style="color: #F8F8F2"> onGeofenceSubscription </span><span style="color: #F92672">=</span><span style="color: #F8F8F2"> BackgroundGeolocation.</span><span style="color: #A6E22E">onGeofence</span><span style="color: #F8F8F2">(</span><span style="color: #FD971F">event</span><span style="color: #F8F8F2"> </span><span style="color: #66D9EF">=&gt;</span><span style="color: #F8F8F2"> {</span>
<span style="color: #F8F8F2">  console.</span><span style="color: #A6E22E">log</span><span style="color: #F8F8F2">(</span><span style="color: #E6DB74">&quot;[onGeofence] &quot;</span><span style="color: #F8F8F2">, event);</span>
<span style="color: #F8F8F2">});</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #F8F8F2">.</span>
<span style="color: #88846F">// Later, removing event-listeners.</span>
<span style="color: #F8F8F2">onLocationSubscription.</span><span style="color: #A6E22E">remove</span><span style="color: #F8F8F2">();</span>
<span style="color: #F8F8F2">onGeofenceSubscription.</span><span style="color: #A6E22E">remove</span><span style="color: #F8F8F2">();</span>
</code></pre>
									</dd>
								</dl>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
						</li>
					</ul>
				</section>
			</section>
		</div>
		<div class="col-3 col-menu menu-sticky-wrap menu-highlight">
			<nav class="tsd-navigation primary menu-sticky">
				<ul class="before-current">
				</ul>
				<ul class="current">
					<li class="current tsd-kind-interface">
						<a href="subscription.html" class="tsd-kind-icon">Subscription</a>
						<ul>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="subscription.html#remove" class="tsd-kind-icon">remove</a>
							</li>
						</ul>
					</li>
				</ul>
				<ul class="after-current">
				</ul>
			</nav>
			<nav class="tsd-navigation secondary menu-sticky">
				<ul class="before-current">
				</ul>
				<ul class="current">
					<li class="current tsd-kind-interface">
						<a href="subscription.html" class="tsd-kind-icon">Subscription</a>
						<ul>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="subscription.html#remove" class="tsd-kind-icon">remove</a>
							</li>
						</ul>
					</li>
				</ul>
				<ul class="after-current">
				</ul>
			</nav>
		</div>
	</div>
</div>
<footer class="with-border-bottom">
	<div class="container">
		<h2>Legend</h2>
		<div class="tsd-legend-group">
			<ul class="tsd-legend">
				<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
			</ul>
			<ul class="tsd-legend">
				<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
			</ul>
			<ul class="tsd-legend">
				<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
			</ul>
		</div>
	</div>
</footer>
<div class="container tsd-generator">
	<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="../assets/js/main.js"></script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4NNZKTE395"></script>
<script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-4NNZKTE395');
    </script>
</body>
</html>